function checkBox(objs) {
    var strArray = document.getElementsByName(objs);
    var chestr = "";
    for (i = 0; i < strArray.length; i++) {
        if (strArray[i].checked == true) {
            chestr += strArray[i].value + ",";
        }
    }
    return chestr;
}

function showDialog(w,h) {
    $("#bg2").css({
        display : "block",
        height : $(document).height()
    });

    var $box = $('.box2');
    $box.css({
        left : ($("body").width() - $box.width()) / w + "px",
        top : ($(window).height() - $box.height()) / h + $(window).scrollTop()
                + "px",
        display : "block"
    });

    $(".close").click(function() {
        $("#bg2,.box2").css("display", "none");
    });
}

function deleteSelected(value, url, param) {
    location.href = url + "?" + param + "=" + value;
}

function deleteExam(url, param1, param2, value1, value2) {
    location.href = url + "?" + param1 + "=" + value1+ "&" + param2 + "=" + value2;
}

function showFrame(obj, value, url, param) {
    $(".showbtn").click(
            function() {
                $("#bg").css({
                    display : "block",
                    height : $(document).height()
                });
                var $box = $('.box');
                $box.css({
                    left : ($("body").width() - $box.width()) / 2 - 20 + "px",
                    top : ($(window).height() - $box.height()) / 2
                            + $(window).scrollTop() + "px",
                    display : "block"
                });
            });
    $(".close").click(function() {
        $("#bg,.box").css("display", "none");
    });
}

function selectedAll(obj, id) {
    if (obj.checked == true) {
        var strArray = document.getElementsByName(id);
        for (var i = 0; i < strArray.length; i++) {
            strArray[i].checked = true;
        }
    } else {
        var strArray = document.getElementsByName(id);
        for (var i = 0; i < strArray.length; i++) {
            // strArray[i].removeAttribute("checked");
            strArray[i].checked = false;
        }
    }
}

function edit(editUrl, data) {
    parent.location.href = editUrl + "?" + encodeURI(data);
}

function sqlencode(str) {
    str = replace(str, "[", "[[]");
    str = replace(str, "_", "[_]");
    str = replace(str, "%", "[%]");
    return str;
}

function reLoad() {
    document.addForm.submit();
    parent.location.reload();
}

function login() {
    var id = document.inForm.userName;
    var password = document.inForm.password;
    var messageLabel = document.getElementById("messageId");
    if (!reg['account'].test(id.value)) {
        messageLabel.innerHTML = "accout include 6-20 characters";
        return;
    }
    if (!reg['password'].test(password.value)) {
        messageLabel.innerHTML = "password include 8-16 characters";
        return;
    }
    document.inForm.submit();
}

function getPoint(obj) {
    obj.style.background = "#D2DAE3";
}

function lostPoint(obj) {
    obj.style.background = "#FFFFFF";
}

function changeUrl() {
    document.getElementById("contentId").src = "http://lsknmfklsdf";
}

function getClick(url) {
    location.href = url;
}

function search(editUrl, param1, param2, param3, param4, value1, value2,
        value3, value4) {
    location.href = editUrl + "?" + param1 + "=" + value1 + "&" + param2 + "="
            + value2 + "&" + param3 + "=" + value3 + "&" + param4 + "="
            + value4;
}

function searchExam(editUrl, param1, param2, param3, param4, param5, value1,
        value2, value3, value4, value5) {
    location.href = editUrl + "?" + param1 + "=" + value1 + "&" + param2 + "="
            + value2 + "&" + param3 + "=" + value3 + "&" + param4 + "="
            + value4 + "&" + param5 + "=" + value5;
}

function searchDraft(editUrl, param1, param2, param3, value1, value2, value3) {
    location.href = editUrl + "?" + param1 + "=" + value1 + "&" + param2 + "="
            + value2 + "&" + param3 + "=" + value3;
}

function getEditAnswer(obj, a, b, c, d) {
    var answer;
    obj.each(function(index) {
        if (this.checked == true) {
            if (this.id == 'A') {
                this.value = a;
            } else if (this.id == 'B') {
                this.value = b;
            } else if (this.id == 'C') {
                this.value = c;
            } else if (this.id == 'D') {
                this.value = d;
            }
            answer = this.value;
        }
    });
    return answer;
}

function getOk() {
    var desc = $("textarea[name='description']").val();
    var a = $("input[name='optionA']").val();
    var b = $("input[name='optionB']").val();
    var c = $("input[name='optionC']").val();
    var d = $("input[name='optionD']").val();
    var answer;
    $("input:radio").each(function(index) {
        if (this.checked == true) {
            if (this.value == 'A') {
                answer = a;
            } else if (this.value == 'B') {
                answer = b;
            } else if (this.value == 'C') {
                answer = c;
            } else if (this.value == 'D') {
                answer = d;
            }
        }
    });

    if (!id) {
        alert("id can't be empty!");
        return false;
    }

    if (!desc) {
        alert("Descriptoin can't be empty!");
        return false;
    }

    if (!a) {
        alert("optionA can't be empty!");
        return false;
    }

    if (!b) {
        alert("optionB can't be empty!");
        return false;
    }

    if (!c) {
        alert("optionC can't be empty!");
        return false;
    }

    if (!d) {
        alert("optionD can't be empty!");
        return false;
    }

    if (!answer) {
        alert("the answer can't be empty!");
        return false;
    }
    return true;
}